﻿using Microsoft.AspNetCore.Mvc;
using yunbo.Model.SSM;
using yunbo.Repositorys.SSMRepositorys;

namespace yunbo.Controllers.SSMControllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class SectionController : Controller
    {
        SectionRepository sectionRepository = new SectionRepository();
        [HttpGet("GetAll")]
        public IActionResult GetAll(int PageNumber, int PageSize)
        {
            FYSection sections = sectionRepository.GetAll(PageNumber, PageSize);
            return Ok(sections);
        }
        [HttpGet("MHCX")]
        public IActionResult MHCX(int PageNumber, int PageSize, int? status, string? sname)
        {
            FYSection sections = sectionRepository.MHCX(PageNumber, PageSize,status,sname);
            return Ok(sections);
        }
        [HttpPost("AddSection")]
        public IActionResult AddSection(TJSection sectiont)
        {
            Section section1 = new Section()
            {
                section_name = sectiont.section_name,
                section_status = 1,
                section_phone = sectiont.section_phone,
                section_charge = sectiont.section_charge,
                section_email = sectiont.section_email,
                section_create_by = sectiont.section_create_by,
                section_create_time = DateTime.Now,
            };
            bool sex = sectionRepository.AddSection(section1) > 0;
            return Ok(sex);

        }
        [HttpPut("UPSection")]
        public IActionResult UPSection(XGSection section)
        {
            Section section2 = new Section()
            {
                section_id = section.section_id,
                section_name = section.section_name,
                section_charge = section.section_charge,
                section_email = section.section_email,
                section_phone = section.section_phone,
                section_update_by = section.section_update_by,
                section_update_time = DateTime.Now,
            };
            bool se2 = sectionRepository.UpSection(section2) > 0;
            return Ok(se2);
        }
        [HttpDelete("DeSection")]
        public IActionResult DeSection(int id)
        {
            bool se3 = sectionRepository.DeSection(id) > 0;
            return Ok(se3);
        }
        [HttpPut("UPstatus")]
        public IActionResult UPstatus(int id, int status)
        {

            bool status1 = sectionRepository.Upstatus(id, status) > 0;
            return Ok(status1);
        }
    }
}
